const btn = document.querySelector('button')
console.log(btn);
window.identity = 'guest'
window.status = '5'
btn.onclick = (e, identity = window.identity, status = window.status) => {
    // const identity = 'guest'
    // const status = 5
    console.log('identity', identity, 'status', status);
    // 字符串
    // let action = actions().get(`${identity}_${status}`)
    // action.call(this)

    // 缓存对象
    // let action = [...actions()].filter(([key, val]) => {
    //     // console.log('key', key, 'val', val);
    //     return key.identity === identity && +key.status === status
    // })
    // action.forEach(([key, val]) => { val.call(this) })

    // 正则
    let action = [...actions()].filter(([key, val]) => {
        console.log('key', key, 'val', val, 'test', key.test(`${identity}_${status}`));
        return key.test(`${identity}_${status}`)
    })
    action.forEach(([key, val]) => val())
}

/**
 * 多元判断：identity： guest|master
 * status: 1|2|3|4|5|6
 * @returns 
 */
const actions = () => {
    const fn1 = () => { console.log('输出1'); }
    const fn2 = () => { console.log('输出2'); }
    const fn5 = () => { console.log('输出5'); }
    const fn = () => { console.log('公共逻辑'); }
    const fn66 = () => { console.log('身份：master'); }

    return new Map([
        // 字符串拼接
        // ['guest_1', () => { console.log('guest_1'); }],
        // ['guest_2', () => { console.log('guest_2'); }],
        // ['guest_3', () => { console.log('guest_3'); }],
        // ['guest_4', () => { console.log('guest_4'); }],
        // ['guest_5', () => { console.log('guest_5'); }]

        // 对象
        // [{ identity: 'guest', status: '1' }, fn1],
        // [{ identity: 'guest', status: '2' }, fn2]

        // 正则
        [/^guest_[1-4]$/, fn1],
        [/^guest_5$/, fn5],
        [/^guest_.*$/, fn],
        [/^master_.*$/, fn66],
    ])
}
console.log(actions());